class BookInfo < ActiveRecord::Base
  belongs_to :category
  attr_accessible :author, :isbn, :name, :numOfVote, :publishDate, :publisher, :vote, :category_id
  
  #Added by Son Nguyen - 11/08/2012 - 11:48pm
  attr_accessible :numberOfVote, :category
  #Added by Son Nguyen - 11/08/2012 - 11:48pm
  
  validates :isbn,  :presence => true
  validates :name,  :presence => true
  validates_uniqueness_of :isbn
  
  has_many :book
  
  def self.findRelativeBook(id, category_id)
    return find_by_sql("select * from book_infos where id != #{id} and category_id = #{category_id}")
  end
  
  def self.search(info)
    if info
      find(:all, :conditions => ['name LIKE ?', "%#{info}%"])
    else
      find(:all)
    end
  end
end
